package com.lanou.dao;

import com.lanou.utils.DBCPUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author lizhongren1.
 */
public class UserDao {

    public Integer findUserByNameAndPassword(String uname, String pwd){

        String sql = "select count(*) from b_user where name=? and password=?";

        Connection conn = DBCPUtils.getConnection();

        QueryRunner qr = new QueryRunner();

        Integer count = 0;
        try {
            System.out.println("------"+count);
            Long re = qr.query(conn,sql, new ScalarHandler<>(1), uname, pwd);
            count = re.intValue();
            System.out.println("======"+count);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        return count;
    }

}
